package com.qf.smsplatform.interfaces.controller;

import com.qf.smsplatform.common.util.IpUtil;
import com.qf.smsplatform.common.vo.R;
import com.qf.smsplatform.interfaces.dto.SmsDTO;
import com.qf.smsplatform.interfaces.service.InterfaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 映射下行接口的Controller
 * @author zjw
 */
@RestController
public class InterfaceController {

    @Autowired
    private InterfaceService interfaceService;

    /**
     * 下行接口
     * @param smsDTO 客户端请求参数
     * @param request  为了获取ip地址
     */
    @RequestMapping("/smsInterface")
    public R smsInterface(@RequestBody SmsDTO smsDTO, HttpServletRequest request){
        // 获取客户端真实的Ip地址
        String ip = IpUtil.getClientIpByReq(request);

        // 将ip封装到DTO中
        smsDTO.setIp(ip);

        // 调用service对参数进行校验
        interfaceService.checkSmsParam(smsDTO);

        // 操作成功
        return R.ok();
    }


}
